package co.fitstart.coach.web.controller;

import java.util.Date;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;

import co.fitstart.coach.entity.security.Login;
import co.fitstart.coach.service.PrincipalService;
import co.fitstart.coach.service.SigninRecordService;
import co.fitstart.coach.web.resolver.Secure;
import co.fitstart.entity.course.schedule.SigninRecord;
import co.fitstart.entity.principal.Principal;

/**
 * 
 * @author dan
 *
 */
@Controller
@RequestMapping("/signin-records")
public class SigninRecordController {
    
    @Autowired
    private PrincipalService principalService;
    
    @Autowired
    private SigninRecordService signinRecordService;
    
    /**
     * 
     * @param login
     * @return
     */
    @RequestMapping(value = "", method = RequestMethod.GET)
    public ModelAndView index(@Secure Login login) {
        ModelAndView modelAndView = new ModelAndView("signin-record/signin-record-index");
        
        Principal coach = principalService.load(Principal.class, login.getId());
        
        int todayAmount = signinRecordService.getDaySigninAmount(coach, new Date());
        modelAndView.addObject("todayAmount", todayAmount);
        
        int totalAmount = signinRecordService.getSigninAmount(coach);
        modelAndView.addObject("totalAmount", totalAmount);
        
        List<SigninRecord> signinRecords = signinRecordService.list(coach);
        modelAndView.addObject("signinRecords", signinRecords);
        
        return modelAndView;
    }

}
